package net.mgsx.product.t2m.modisco.impact.analyser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.mgsx.product.t2m.modisco.ModiscoTestCase;
import net.mgsx.product.t2m.modisco.MultipleElementsFoundException;
import net.mgsx.product.t2m.modisco.impact.AnalysisInformation;

import org.eclipse.gmt.modisco.java.ASTNode;
import org.eclipse.gmt.modisco.java.AbstractTypeDeclaration;
import org.eclipse.gmt.modisco.java.CompilationUnit;
import org.eclipse.gmt.modisco.java.MethodDeclaration;
import org.eclipse.gmt.modisco.java.Model;
import org.junit.Assert;
import org.junit.Test;

public class FileImpactAnalyserTestCase extends ModiscoTestCase {

	@Test
	public void testAnalyseNominal() throws MultipleElementsFoundException
	{
		final Model model = loadModel("testModels/tc1.javaxmi");
		final FileImpactAnalyser analyser = new FileImpactAnalyser();
		final List<ASTNode> modifiedNodes = new ArrayList<ASTNode>();
		final AbstractTypeDeclaration mapper = findElement(model, "MapperModiscoUmlImpl", AbstractTypeDeclaration.class);
		
		final MethodDeclaration method = findElement(mapper, "addUsageLink", MethodDeclaration.class);
		Assert.assertNotNull(method);
		modifiedNodes.add(method);
		
		final Map<ASTNode, AnalysisInformation> results = analyser.analyse(modifiedNodes);
		Assert.assertNotNull(results);
		Assert.assertEquals(15, results.size());
		
		final CompilationUnit unit = findElement(model, "MapperModiscoUmlImpl.java", CompilationUnit.class);
		Assert.assertNotNull(unit);
		final AnalysisInformation info = results.get(unit);
		Assert.assertNotNull(info);
		Assert.assertTrue(info.impacted);
		Assert.assertEquals(635, info.nbInstructions);
	}
	
}
